//
//  HMMainViewController.swift
//  VVeibo21
//
//  Created by 李浩杰 on 16/10/22.
//  Copyright © 2016年 李浩杰. All rights reserved.
//

import UIKit

class HMMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = HMTabBar()
        
        //通过kvc给计算属性：只读属性赋值
        setValue(tabBar, forKey: "tabBar")
        
        
        //添加标签控制器
        addChildViewController(vc: HMHomeViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(vc: HMMessageViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(vc: HMDiscoverViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(vc: HMProfileViewController(), title: "我", imgName: "tabbar_profile")
    }
    
    
    
    // MARK: - 设置视图
    
    /// 添加子控制器方法
    ///
    /// - parameter vc:      子控制器
    /// - parameter title:   名字
    /// - parameter imgName: 图片名字
    private func addChildViewController(vc: UIViewController, title: String, imgName: String) {
        vc.title = title
        //设置文字颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : HMTHEMECOLOR], for: UIControlState.selected)
        vc.tabBarItem.image = UIImage(named: imgName)
        // 选中的图片(alwaysOriginal 原生渲染方式)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        //添加nav导航控制器
        let vcNav = HMNavigationController(rootViewController: vc)
        addChildViewController(vcNav)
        
    }

}
